package ar.edu.itba.it.pdc.configuration.models;

import java.net.InetAddress;
import java.util.Comparator;

public class Comparators {
	
	public static Comparator<InetAddress> getIpComparator() {
		return new Comparator<InetAddress>() {
			public int compare(InetAddress a, InetAddress b) {
				byte[] aa = a.getAddress();
				byte[] bb = b.getAddress();

				for (int i=0; i<4; i++) {
					if ( aa[i] != bb[i] ) {
						return (aa[i] & 0xff) - (bb[i] & 0xff);
					}
				}
				return 0;
			}
		};
	}
}
